#include <wx/bmpbuttn.h>
#include "wxsbitmapbutton.h"

#include <prep.h>

namespace {
  wxsRegisterItem<wxsBitmapButton> Reg( _T( "BitmapButton" ), _T( "位图按钮" ), wxsTWidget, _T( "标准" ), 360 );
  WXS_ST_BEGIN( wxsBitmapButtonStyles, _T( "wxBU_AUTODRAW" ) )
  WXS_ST_CATEGORY( "wxBitmapButton" )
  WXS_ST( wxBU_LEFT )
  WXS_ST( wxBU_TOP )
  WXS_ST( wxBU_RIGHT )
  WXS_ST( wxBU_BOTTOM )
  WXS_ST( wxBU_AUTODRAW )
  WXS_ST_DEFAULTS()
  WXS_ST_END()
  WXS_EV_BEGIN( wxsBitmapButtonEvents )
  WXS_EVI( EVT_BUTTON, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEvent, Click )
  WXS_EV_END()
}

wxsBitmapButton::wxsBitmapButton( wxsItemResData* Data ):
  wxsWidget(
    Data,
    &Reg.Info,
    wxsBitmapButtonEvents,
    wxsBitmapButtonStyles ),
  IsDefault( false ) {}

void wxsBitmapButton::OnBuildCreatingCode() {
  switch( GetLanguage() ) {
    case wxsCPP: {
      AddHeader( _T( "<wx/bmpbuttn.h>" ), GetInfo().ClassName, hfInPCH );
      Codef( _T( "%C(%W, %I, %i, %P, %S, %T, %V, %N);\n" ), &BitmapLabel, _T( "wxART_BUTTON" ) );
      if( !BitmapDisabled.IsEmpty() ) {
        Codef( _T( "%ASetBitmapDisabled(%i);\n" ), &BitmapDisabled, _T( "wxART_BUTTON" ) );
      }
      if( !BitmapSelected.IsEmpty() ) {
        Codef( _T( "%ASetBitmapSelected(%i);\n" ), &BitmapSelected, _T( "wxART_BUTTON" ) );
      }
      if( !BitmapFocus.IsEmpty() ) {
        Codef( _T( "%ASetBitmapFocus(%i);\n" ), &BitmapFocus, _T( "wxART_BUTTON" ) );
      }
      if( IsDefault ) {
        Codef( _T( "%ASetDefault();\n" ) );
      }
      BuildSetupWindowCode();
      return;
    }
    case wxsUnknownLanguage:
    default: {
      wxsCodeMarks::Unknown( _T( "wxsBitmapButton::OnBuildCreatingCode" ), GetLanguage() );
    }
  }
}

wxObject* wxsBitmapButton::OnBuildPreview( wxWindow* Parent, long Flags ) {
  wxBitmapButton* Preview = new wxBitmapButton( Parent, GetId(), BitmapLabel.GetPreview( wxDefaultSize ), Pos( Parent ), Size( Parent ), Style() );
  if( !BitmapDisabled.IsEmpty() ) {
    Preview->SetBitmapDisabled( BitmapDisabled.GetPreview( wxDefaultSize ) );
  }
  if( !BitmapSelected.IsEmpty() ) {
    Preview->SetBitmapSelected( BitmapSelected.GetPreview( wxDefaultSize ) );
  }
  if( !BitmapFocus.IsEmpty() ) {
    Preview->SetBitmapFocus( BitmapFocus.GetPreview( wxDefaultSize ) );
  }
  if( IsDefault ) {
    Preview->SetDefault();
  }
  return SetupWindow( Preview, Flags );
}

void wxsBitmapButton::OnEnumWidgetProperties( M_Code_unused long Flags ) {
  WXS_BITMAP( wxsBitmapButton, BitmapLabel, _T( "Bitmap" ), _T( "bitmap" ), _T( "wxART_OTHER" ) )
  WXS_BITMAP( wxsBitmapButton, BitmapDisabled, _T( "Disabled bmp." ), _T( "disabled" ), _T( "wxART_OTHER" ) )
  WXS_BITMAP( wxsBitmapButton, BitmapSelected, _T( "Pressed bmp." ), _T( "selected" ), _T( "wxART_OTHER" ) )
  WXS_BITMAP( wxsBitmapButton, BitmapFocus, _T( "Focused bmp." ), _T( "focus" ), _T( "wxART_OTHER" ) )
  WXS_BOOL( wxsBitmapButton, IsDefault, _T( "Is default" ), _T( "default" ), false )
}
